package com.magictower.primary.receiver;

import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import java.util.List;

/**
 * 消除所有进程
 * @author kejunzhan
 * @since 2017/12/18
 */

public class KillProcessAllReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
        List<RunningAppProcessInfo> lists = am.getRunningAppProcesses();
        for (RunningAppProcessInfo list : lists) {
            am.killBackgroundProcesses(list.processName);
        }
        Toast.makeText(context, "清理完毕", Toast.LENGTH_SHORT).show();
    }
}
